using System.Windows.Forms;

namespace com.zjgis.control
{
    public partial class InputBox : Form
    {
        private static InputBox box;

        private InputBox()
        {
            InitializeComponent();
            textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);
            KeyDown += textBox1_KeyDown;
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Escape)
            {
                Close();
            }
            else if (e.KeyData == Keys.Enter)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }

        public string GetInputText()
        {
            return textBox1.Text;
        }

        public static InputBox Show(string text,string inputtext)
        {
            if (box == null)
            {
                box = new InputBox();
            }
            box.Text = text;
            box.textBox1.Text = inputtext;
            box.StartPosition = FormStartPosition.Manual;
            box.Location = Cursor.Position;
            box.ShowDialog();
            return box;
        }

        public new static InputBox Show()
        {
            if (box == null)
            {
                box = new InputBox();
            }
            box.textBox1.Text = "";
            box.StartPosition = FormStartPosition.Manual;
            box.Location = Cursor.Position;
            box.ShowDialog();
            return box;
        }

        private void InputBox_Activated(object sender, System.EventArgs e)
        {
            textBox1.Focus();
        }

    }
}